package com.pearadmin.pro.modules.paper.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pearadmin.pro.modules.examUtils.BeanMapper;
import com.pearadmin.pro.modules.examUtils.PagingReqDTO;
import com.pearadmin.pro.modules.paper.dto.RepoDTO;
import com.pearadmin.pro.modules.paper.dto.response.RepoRespDTO;
import com.pearadmin.pro.modules.paper.entity.Repo;
import com.pearadmin.pro.modules.paper.mapper.RepoMapper;
import com.pearadmin.pro.modules.paper.service.RepoService;
import org.springframework.stereotype.Service;

import java.util.Date;


@Service
public class RepoServiceImpl extends ServiceImpl<RepoMapper, Repo> implements RepoService {

    @Override
    public IPage<RepoRespDTO> paging(PagingReqDTO<RepoDTO> reqDTO) {

        //创建分页对象
        Page page = new Page(reqDTO.getCurrent(), reqDTO.getSize());

        return baseMapper.paging(page, reqDTO.getParams());
    }
    @Override
    public void save(RepoDTO reqDTO) {
        reqDTO.setCreateTime(new Date());
        reqDTO.setUpdateTime(new Date());

        //复制参数
        Repo entity = new Repo();
        BeanMapper.copy(reqDTO, entity);
        this.saveOrUpdate(entity);
    }
    @Override
    public void refreshStat(String repoId) {
        baseMapper.refreshStat(repoId);
    }
}
